﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DevelopTools
{
    /// <summary>
    /// 粒子系统元素
    /// </summary>
    [SerializeField]
    public class ParticleItem : MonoBehaviour
    {
        /// <summary>
        /// 播放的粒子
        /// </summary>
        private ParticleSystem particle;
        /// <summary>
        /// 声音片段：可不添加
        /// </summary>
        public AudioClip sound;
        /// <summary>
        /// 声音播放器
        /// </summary>
        private AudioSource audioSource;
        private void Awake()
        {
            Init();
        }
        /// <summary>
        /// 初始化
        /// </summary>
        private void Init()
        {
            if (sound != null)
            {
                audioSource = gameObject.AddComponent<AudioSource>();
                audioSource.clip = sound;
                audioSource.playOnAwake = false;
            }
            particle = GetComponent<ParticleSystem>();
        }
        /// <summary>
        /// 播放粒子特效
        /// </summary>
        public void Play()
        {
            particle.Play();
            PlaySound();
        }
        private void PlaySound()
        {
            if (sound == null)
            {
                return;
            }
            audioSource.Play();
        }

    }
}